/*
 * Copyright (C) 2004, Velocityme Partnership
 * RoleValueActionForm.java
 *
 * Created on 09 October 2004, 06:13
 */

package com.velocityme.www.actionforms.nodeactionforms;

import java.io.Serializable;
import java.util.Collection;
import java.util.Map;
import java.util.TreeMap;
import org.apache.struts.action.*;

/**
 *
 * @author  Robert
 */
public class RoleValueActionForm extends NodeValueActionForm {
    
    private class Permission implements Serializable {
        Integer m_permissionId;
        Boolean m_permissionEnabled;
    }
    
    private Boolean m_isRecursive;
    private Map m_permissionMap;

    /** Creates a new instance of RoleValueActionForm */
    public RoleValueActionForm() {
        m_permissionMap = new TreeMap();
    }
    
    public void reset(ActionMapping mapping, javax.servlet.http.HttpServletRequest request) {
        m_isRecursive = new Boolean(false);
        m_permissionMap.clear();
    }
    
    public Boolean getIsRecursive() {
        return m_isRecursive;
    }
    
    public void setIsRecursive(Boolean isRecursive) {
        m_isRecursive = isRecursive;
    }
    
    public Collection getPermissions() {
        return m_permissionMap.keySet();
    }
    
    public Boolean getPermissionEnabled(String key) {
        return ((Permission)m_permissionMap.get(key)).m_permissionEnabled;
    }
    
    public void setPermissionEnabled(String key, Boolean enabled) {
        if (!m_permissionMap.containsKey(key))
            m_permissionMap.put(key, new Permission());
        ((Permission)m_permissionMap.get(key)).m_permissionEnabled = enabled;
    }
    
    public Integer getPermissionId(String key) {
        return ((Permission)m_permissionMap.get(key)).m_permissionId;
    }
    
    public void setPermissionId(String key, Integer permissionId) {
        if (!m_permissionMap.containsKey(key))
            m_permissionMap.put(key, new Permission());
        ((Permission)m_permissionMap.get(key)).m_permissionId = permissionId;
    }
    
}
